//Hi,
//
//This works for me!

/////////////////////////////////////////////////////////////
// Reads one byte from the EEprom at the specified address //
// and returns it                                          //
/////////////////////////////////////////////////////////////
unsigned char ReadByteFromEE(const unsigned char address)
{
	unsigned char byte;                     // Variable hold the data that is read

	EEADR = address;                        // Read from this address

	EEPGD = 0;                              // Point to EE memory
	RD	  = 1;                              // Initiate a read cycle

	byte = EEDATA;                          // Fetch byte from dataregister
	return byte;                            // Return the read byte
}

////////////////////////////////////////////////////////////
// Writes one byte to the EEprom at the specified address //
////////////////////////////////////////////////////////////
void WriteByteToEE(unsigned char data, const unsigned char address)
{
	EEADR  = address;                       // Address to write to
	EEDATA = data;                          // Data to write

	WREN   = 1;                             // Enable writes to the EEProm
	GIE    = 0;                             // Disable interrupts during write

	EECON2 = 0x55;                          // Write "password" to EECON2
	EECON2 = 0xAA;
	WR     = 1;                             // Initiate a write cycle

	while(!EEIF);                           // Wait for write to complete
	WREN   = 0;                             // Disable writes to EEProm
	EEIF   = 0;                             // Clear "write complete" flag
}

//Venlig hilsen /Best Regards
//Henrik Nowak
//SW Developer
//
//IMPC Solutions
//Gudrunsvej 6, 3th
//DK-8220 Brabrand
//Phone : +45 2032 4321
//Direct: +45 2022 9598
//Email : hno@impc.dk